/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAOS.DAOSAUTORES;

import Entidades.EntidadesAutores.Alumno;
import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author LUIGI
 */
@Stateless
@LocalBean
public class AlumnoDAO {

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    @PersistenceContext
    EntityManager em;
    
    public void crear(Alumno a) {
        em.persist(a);
    }
    
    public void actualizar(Alumno a) {
        em.merge(a);
    }
    
    public void borrar(Integer id) {
        Alumno alu = em.find(Alumno.class, id);
        em.remove(alu);
    }
    
    public void guardar(Alumno a) {
        if (a.getIdAlumno() == null) {
            crear(a);
        } else {
            actualizar(a);
        }
    }
    
    public List<Alumno> BuscarTodosAlumno() {
        return em.createNamedQuery("Alumno.findAll", Alumno.class).getResultList();
    }
    
    public List<Alumno> BuscarAlumno(String cadena) {
        return em.createNamedQuery("Alumno.findByIdAlumno", Alumno.class)
                .setParameter("alumno", cadena).getResultList();
    }
}
